home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NARexx / PBar.dopus5 < prev    next >
Text File  |  1995-08-18  |  6KB  |  158 lines

  1. /* Progress-Bar for Directory Opus 5.
  2.    By Leo Davidson ("Nudel", P0T-NOoDLE/Gods'Gift Utilities)
  3.  
  4. $VER: PBar.dopus5 1.4 (18.8.95)
  5.  
  6.    This ARexx script will add a progress bar (like when deleting files)
  7.    to external commands which are run on all the selected entries in a
  8.    lister.
  9.  
  10. Call as:
  11. ------------------------------------------------------------------------------
  12. ARexx    PBar.dopus5 {Qp} "<1>" "<2>"
  13. ------------------------------------------------------------------------------
  14. Where <1> is the AmigaDOS command to be run for each file.
  15.  Insert "!!f!!" (without quotes) where you would like the full path to the
  16.  selected file (you can insert it more than once, if you require).
  17. <2> is the progress window title.
  18.  
  19. If <1> or <2> have any spaces in them, "put quotes around them".
  20.  
  21. The "Do All Files" switch MUST be turned *_OFF_*!!!
  22.  
  23. e.g.
  24. ------------------------------------------------------------------------------
  25. ARexx    DOpus5:ARexx/PBar.dopus5 {Qp} "C:PackIt !!f!! CRUNCH" "Packing files:"
  26. ------------------------------------------------------------------------------
  27.  
  28. Note: The command you use must be able to handle "filenames with quotes".
  29.  
  30. TO DO:
  31. ------
  32. - Convert this to a nice, fast assembler program - once I get to grips with
  33.   how to send Rexx messages via rexxsyslib.library (HELP!).
  34. - Make it rescan all selected entries.
  35.   (Short of making it rescan the entire dir, which you can do as a switch
  36.   within DOpus, I don't think there is a way to emulate "Reload each file"
  37.   via an ARexx script, at least in the current version of DOpus5.)
  38. - Perhaps propper support for all the {} type codes, not just {f}.
  39. - ONLY DIRS and ONLY FILES options.
  40.   (If you don't want it to act on files or on dirs, simply don't select them!)
  41. - Take a filetype-ID so that only files matching it are acted on.
  42.   (this would actually be a pain to impliment - I'm not about to).
  43.  
  44.    v1.02 -> v1.03 - Now uses stem variables for getting the lister handle.
  45.                     Some minor tidying up.
  46.                     Now checks to make sure the DOPUS.x port exists.
  47.     v1.03 -> v1.4 - Now uses Show() instead of ShowList(). (Thanks Stoebi)
  48.                     Style Guide compliant version numbering and $VER string.
  49.  
  50.  
  51. ---- Setup --------------------------------------------------------------------
  52.    You should edit the SepBar below to look right with your output-window
  53.    setup (use the script and you'll see what it does). */
  54. SepBar = "-----------------------------------------------------------------------------------"
  55.  
  56. options results
  57. options FAILAT 99
  58. signal on syntax;signal on ioerr        /* Error trapping */
  59.  
  60. /*- Parse the command-line --------------------------------------------------*/
  61. CmdLine = ARG(1)
  62. DOpusPort = GetCmdWord()
  63. UserCommand = GetCmdWord()
  64. UserTitle = GetCmdWord()
  65.  
  66. If DOpusPort="" THEN Do
  67.     Say "Not correctly called from Directory Opus 5!"
  68.     Say "Load this ARexx script into an editor for more info."
  69.     EXIT
  70.     END
  71. If ~Show("P",DOpusPort) Then Do
  72.     Say DOpusPort "is not a valid port."
  73.     EXIT
  74.     End
  75. Address value DOpusPort
  76.  
  77. If UserTitle="" Then UserTitle = "Doing all files..."
  78.  
  79. lister query source stem source_handle.
  80.  
  81. IF source_handle.count = 0 | source_handle.count = "SOURCE_HANDLE.COUNT" Then Do
  82.     dopus request '"You must have a SOURCE lister!" OK'
  83.     EXIT
  84.     End
  85.  
  86. lister set source_handle.0 busy 1
  87.  
  88. lister query source_handle.0 numselentries    /* Get info about selected */
  89. Lister_NumSelEnt = RESULT            /* entries & path to them */
  90. lister query source_handle.0 path
  91. Lister_Path = Strip(RESULT,"B",'"')
  92.  
  93. If Lister_NumSelEnt = "RESULT" | Lister_Path = "RESULT" Then Do
  94.     lister set source_handle.0 busy 0
  95.     EXIT
  96.     END
  97.  
  98. /*-- The Progress Bar ---------------------------------------------------------
  99. A progress bar will display how many of the selected files have been done.
  100. This means the max-number argument is Lister_NumSelEnt.
  101. For each selected entry, the "Do i..." loop updates the progress bar,
  102. builds and executes the user-defined command, and then de-selects.
  103. -----------------------------------------------------------------------------*/
  104. lister set source_handle.0 progress Lister_NumSelEnt UserTitle
  105.  
  106. Do i=1 to Lister_NumSelEnt
  107.     lister query source_handle.0 firstsel
  108.     Temp_Name = RESULT
  109.     lister select source_handle.0 Temp_Name 0
  110.     Temp_Name = Strip(Temp_Name,"B",'"')
  111.     lister set source_handle.0 progress name Temp_Name
  112.     lister set source_handle.0 progress count i
  113.     lister query source_handle.0 abort
  114.     IF RESULT=1 THEN BREAK        /* If they aborted, break the loop */
  115.  
  116.     Temp_Name = '"'||Lister_Path||Temp_Name||'"'
  117.     Temp_Exec = Upper(UserCommand)
  118.     Do While Index(Temp_Exec,"!!F!!") ~= 0
  119.         Temp_Pos = Index(Temp_Exec,"!!F!!")
  120.         Temp_Exec = DelStr(Temp_Exec,Temp_Pos,"5")
  121.         Temp_Exec = Insert(Temp_Name,Temp_Exec,Temp_Pos-1)
  122.         END
  123.     Address Command Temp_Exec
  124.     Say SepBar
  125.     END
  126.  
  127. /*-- Restore the Lister for normal use --------------------------------------*/
  128. syntax:;ioerr:                /* In case of error, jump here */
  129. lister clear source_handle.0 progress
  130. lister refresh source_handle.0
  131. lister set source_handle.0 busy 0
  132.  
  133. EXIT
  134.  
  135.  
  136. /*- Function for Command-Line parsing -----------------------------------------
  137.  ARexx's "PARSE ARG" is rank. It isn't very good at handling arguments with
  138.  "quotes" (especially when the quotes are optional), and inserts spaces
  139.  where you don't want them sometimes. I don't have the docs to RexxDosSupport,
  140.  so I wrote my own function which extracts the next argument from the string
  141.  "CmdLine", respecting quotes, and not adding extra spaces at either side.
  142. -----------------------------------------------------------------------------*/
  143. GetCmdWord:
  144.     Temp_CmdWord = Word(CmdLine,1)
  145.     CmdLine = DelWord(CmdLine,1,1)
  146.  
  147.     If Left(Temp_CmdWord,1) = '"' Then Do Forever
  148.         If Right(Temp_CmdWord,1) = '"' Then Break
  149.         If Words(CmdLine) = "0" Then Call BadCmd_Quotes
  150.         Temp_CmdWord = Temp_CmdWord||" "||Word(CmdLine,1)
  151.         CmdLine = DelWord(CmdLine,1,1)
  152.         End
  153.     Return Strip(Temp_CmdWord,"B",'"')
  154.  
  155. BadCmd_Quotes:
  156.     dopus request '"PBar.dopus5: Bad Command Line.' || X2C(0A) || 'Unclosed quotes in string." OK'
  157.     EXIT
  158.